package com.wgo.precise.client.ui.view.projecttree;

import static com.wgo.precise.client.ui.controller.PrecisePluginImage.IMG_CREATE_PROJECT;

import com.wgo.precise.client.ui.controller.RequirementPlugin;
import com.wgo.precise.client.ui.model.ProjectWrapper;
import com.wgo.precise.client.ui.model.facade.INodeParent;

import remato.domain.common.Project;
/**
 * 
 * @author Petter L. H. Eide
 * @version $Id: CreateProjectAction.java,v 1.3 2006-01-31 22:40:30 petterei Exp $
 */
public class CreateProjectAction extends CreateAction<ProjectWrapper, INodeParent> {
    
    public CreateProjectAction(INodeParent item) {
        super(createText(Project.class.getSimpleName()), item, IMG_CREATE_PROJECT.getImageDescriptor());
    }
    
    /**
     * @see com.wgo.precise.client.ui.view.projecttree.CrudAction#run()
     */
    @Override
    public void run() {
        Project domainProject = RequirementPlugin.getInstance().getSession().getDomainSession().createConcept(Project.class);
        ProjectWrapper project = RequirementPlugin.getInstance().getSession().getWrapperFactory().getWrapper(domainProject);
        INodeParent parent = getItem();
        if (parent == null ) {
        	parent = RequirementPlugin.getInstance().getSession().getWrapperFactory().getSystem(ProjectWrapper.class);
            setItem(parent);
        }
        project.setParent(parent);
        super.setNewItem(project);
        super.run();
    }
}
